package com.lagou.service.pojo;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

public class RpcDecoder extends ByteToMessageDecoder {
	
    private Class<?> clazz;

    private Serializer serializer;

    public RpcDecoder(Class<?> clazz, Serializer serializer) {

        this.clazz = clazz;

        this.serializer = serializer;
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        int Length = byteBuf.readInt();
        byte[] data = new byte[Length];
        byteBuf.readBytes(data);
        RpcRequest deserialize = serializer.deserialize(RpcRequest.class, data);
//        System.out.println(deserialize.toString());
        list.add(deserialize);
    }
}
